package com.adms.controller;

import java.util.Date;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.adms.domain.Message;
import com.adms.service.MessageService;

@RequestMapping("message")
@RestController
public class MessageController {

	@Autowired
	private MessageService messageService;
	
	@GetMapping("{messageId}")
	public Object getByMessageId(@PathVariable("messageId") Integer messageId) {
		return messageService.getByMessageId(messageId);
	}
	
	@GetMapping
	public Object list(Message message,String timeField,Date start,Date end,String orderByClause,
			@RequestParam(defaultValue = "1") Integer pageNum,
			@RequestParam(defaultValue = "5") Integer pageSize,
			@RequestParam(defaultValue = "5") Integer navigatePages) {
		return messageService.list(message,timeField,start,end,orderByClause,pageNum,pageSize,navigatePages);
	}
	
	@PostMapping("click")
	public Object click(@RequestParam("messageId") Integer messageId) {
		return messageService.click(messageId);
	}
}
